package com.company._3Method;

import com.company._class01.Person;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestMethodDemo {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Class c= Person.class;
        Person p=new Person();
        p.setName("劳务");
        //得到所有公开方法,包含父类
//        Method[] ms=c.getMethods();
//        for(Method m:ms){
//            System.out.println(m);
//        }
        //得到本类所有方法，不包含父类
//        Method[] ms=c.getDeclaredMethods();
//        for(Method m:ms){
//            System.out.println(m);
//        }

//        Method m=c.getMethod("work",new Class[]{});
//        System.out.println(m);

//        Method m=c.getDeclaredMethod("work",new Class[]{});
//        m.setAccessible(true);
//        m.invoke(p);
//        System.out.println(m);

        Method m=c.getMethod("work1");
        m.invoke(null);
    }
}
